<?php


namespace app\common\model;


use think\Model;

class Withdrawal extends Model
{
    // 表名
    protected $name = 'withdrawal';
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    // 追加属性
    protected $append = [
        'bank_type_text',
        'status_text'
    ];

    public function getAuditTimeAttr($value)
    {
        return $value ? date('Y-m-d H:i', $value) : '';
    }

    public function getCreatetimeAttr($value)
    {
        return $value ? date('Y-m-d H:i', $value) : '';
    }

    public function getUpdatetimeAttr($value)
    {
        return $value ? date('Y-m-d H:i', $value) : '';
    }


    public function getBankTypeTextAttr($value, $data)
    {
        $value = $value ?: ($data['bank_type'] ?? 1);
        return is_numeric($value) ? ($value == 1 ? __('Bank card') : __('Wechat wallet')) : $value;
    }

    public function getStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['status'] ?? 0);
        if (!is_numeric($value)) {
            return $value;
        }
        switch ($value) {
            case 0:
                return __('Under review');
            case 1:
                return __('Withdraw successful');
            case 2:
                return __('Withdraw failed');
            default:
                return '';
        }
    }
}